package com.example.meterial_design;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private android.support.v7.widget.Toolbar tb;
    private CardView mIdCv;
    private ImageView mIdImg;
    private int count =0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initFindViewById();


        setSupportActionBar(tb);

        mIdCv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                runAnim();
            }
        });

    }

    private void runAnim() {
        mIdCv.animate().translationX(100 + count).setDuration(1000).start();
        count += 10;
    }

    private void initFindViewById() {
        tb = findViewById(R.id.my_tb);
        mIdCv = findViewById(R.id.id_cv);
        mIdImg = findViewById(R.id.id_img);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.tab_add:
                ToastUtil.showAtOnce(MainActivity.this, "tab_add");
                break;
            case R.id.tab_about:
                ToastUtil.showAtOnce(MainActivity.this, "about");
                break;
            case R.id.tab_before:
                ToastUtil.showAtOnce(MainActivity.this, "defore");
                break;
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    //菜单栏点击

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolbar_menu,menu);
        return true;
    }


}
